//
//  CourseListCell.m
//  优学荟管理系统
//
//  Created by 星道 on 17/6/27.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "CourseListCell.h"

@implementation CourseListCell
{
    IBOutlet UILabel *_StatusLabel;
    IBOutlet UILabel *_ID;
    IBOutlet UILabel *_Title;
}

- (void)setModel:(CourseListModel *)Model
{
    _Model = Model;
    _ID.text = [Model.ID stringValue];
    _Title.text = Model.name;

    self.upButton.selected = [Model.sellStatus integerValue];

    /** 套餐列表进来的话就隐藏掉上下架的按钮 */
    self.upButton.hidden = Model.isTaoCan;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    // 修改按钮的状态
    [self.upButton setTitle:@"上架" forState:(UIControlStateNormal)];
    [self.upButton setTitle:@"下架" forState:(UIControlStateSelected)];
    [self.upButton setTitleColor:[UIColor grayColor] forState:(UIControlStateSelected)];
    [self.upButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [self.upButton setBackgroundImage:[self createImageWithColor:ColorRGB(240, 240, 240)] forState:(UIControlStateSelected)];
    [self.upButton setBackgroundImage:[UIImage imageNamed:@"btn_putaway_default"] forState:(UIControlStateNormal)];
}

//颜色转换图片
- (UIImage*)createImageWithColor:(UIColor*) color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

@end
